<script type="text/javascript">
    $(document).ready( function() {

        $(function() {
            $('#loading').ajaxStart(function(){
                $(this).fadeIn();
            }).ajaxStop(function(){
                $(this).fadeOut();
            });

            $('#menu_cm a').click(function() {
                var url = $(this).attr('href');
                $('#container').load(url);
                return false;
            });

            var w = parseInt($('#week_count').val());
            for(var a=0;a<=w;a++){
                $('#click'+a).click(function(){

                    if ($("#container").is(":hidden")) {
                        $("#container").slideDown("slow");
                        //$('#click').text('Tutup');
                    } else {
                        $("#container").slideUp("slow");

                    }
                });
            }

        });
    });
</script>
<style type="text/css">
    #loading { position: absolute; top: 0; left: 0; color: white; background-color: red; padding: 5px 10px; font: 12px Arial; }
</style>
<?php $this->load->helper('HTML'); 
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
<h2 class="title">OMSET PRA CALON MANAGER</h2>

<table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
    <thead>
        <?php if(isset($error)) {?>
        <tr>
            <td colspan="5">
                    <?php echo $error?>
            </td>
        </tr>
            <?php }else { ?>
        <tr  align="center" class="table" >
    <input type="hidden" id="week_count" value="<?php echo count($weeks)?>">
    <th ><?php echo $bulan . " " . $tahun?></th>
        <?php for($i=0;$i<count($weeks);$i++):?>
    <th >Minggu Ke- <?php echo $weeks[$i]->intid_week;?></th>
        <?php endfor;?>
    <th >Total</th>

</tr>
</thead>
<tbody>

    <!-- ============isi ============ -->
    <tr class='data'>
        <td>Penjualan Pribadi</td>
            <?php
            $total=0;
            for($i=0;$i<count($week_pribadi);$i++):?>
        <td align="center">
                    <?php

			$_nokartu001 = $_POST['strkode_dealer'];
			$_week = $weeks[$i]->intid_week;
			$penjualanpribadi001 = $this->Cm_model->penjualanpribadi_or001($_nokartu001, $_week);
			if(!empty($penjualanpribadi001[0]->total)) {
				$prpr = $penjualanpribadi001[0]->total;
				$total += $prpr;
			}else {
				$prpr=0;
			}
				 
			echo $prpr;

                    /*if(!empty($week_pribadi[$i][0]->total)) {
                        echo $week_pribadi[$i][0]->total;
                        $total = $total + $week_pribadi[$i][0]->total;
                    }else {
                        echo "0";
                    }*/
                    ?>
        </td>
            <?php endfor;?>
        <td align="center">
                <?php //$total = 0;
                echo number_format($total)?>
        </td>
    </tr>

    <tr class="data">
        <td>Rekrut Baru Pribadi</td>
            <?php
            $total_rekrut=0;
            $ar=array();
            $cek='';
            for($i=0;$i<count($week_rekrut);$i++):?>
        <td align="center">
                    <?php
                    
                    if(!empty($week_rekrut[$i][0]->total)) {
                        $total_rekrut = $total_rekrut + $week_rekrut[$i][0]->total;
                        $tt = $week_rekrut[$i][0]->total;
                       //$ar[]=$week_rekrut[$i][0]->total;
                       
                    }else {
                        //echo "0";
                        $tt=0;
                    }
                     if($tt==0){
                            $cek = 0;
                        }else{
                            $cek=1;
                        }
                    echo $tt;
                   
                    ?>
        </td>
            <?php endfor;?>
        <td align="center">
                <?php echo $total_rekrut . " Orang"?>
        </td>
    </tr>
    <tr class="data">
        <td>Penjualan Rekrut</td>
            <?php
            $total_jualrekrut=0;
            for($i=0;$i<count($penjualanrekrut);$i++):?>
        <td align="center">
                    <?php
$_nokartu001 = $_POST['strkode_dealer'];
$_week = $weeks[$i]->intid_week;
                    //print_r($penjualanrekrut[$i][0]->total);
								$penjualanrekrut001 = $this->Cm_model->penjualanrekrut_or($_nokartu001, $_week);
								if(!empty($penjualanrekrut001[0]->total)) {
									$pr = $penjualanrekrut001[0]->total;
									$total_jualrekrut += $pr;
								}else {
									$pr=0;
								}
								 
								echo $pr;
                    /*if(!empty($penjualanrekrut[$i])) {
                        $pr = number_format($penjualanrekrut[$i][0]->total);
                        $week = $penjualanrekrut[$i][0]->intid_week;
                        $total_jualrekrut = $total_jualrekrut + $penjualanrekrut[$i][0]->total;
                        ?>
            <div id="menu_cm" style="height: 40px; width: 50px">
                            <?php  echo anchor ('calon_manager/view_rekrut4/'.$strkode."/". $week, ($pr), array('id' =>"click".$i));?>
            </div>
            
            <?php
                    }else {
                        $pr = "0,00";
                        $week = 0;
                        echo $pr;
                    }*/
                    ?>

        </td>
            <?php endfor;?>

        <td align="center">
                <?php echo number_format($total_jualrekrut)?>
        </td>
    </tr>

    <tr class="data">
        <td>&nbsp;</td>
        <td align="center" colspan="<?php echo count($weeks)?>">Total Penjualan Group Pra CM Dalam satu bulan</td>
        <td align="center"><?php $tsatubulan = ($total + $total_jualrekrut);
                if($tsatubulan >= 1600000) {
                    $allowSave = '';
                }else {
                    $allowSave = 'disabled';
                }
                echo number_format($tsatubulan)?></td>
    </tr>

</tbody>
    <?php } ?>
</table>

<div id="loading" style="display:none">Loading...</div>
<div id="container" style="width:400px; height: 100px; display:none;">
		No Display Data
</div>
<p>&nbsp;</p>
<?php
if(($total_rekrut >=4)&&($tsatubulan >= 1600000)&&($cek!=0)) {
    ?>
<form method="post" id="myForm">
    <table width="95%" border="0" cellpadding="0" cellspacing="0" id="data" align="left">
        <tr>
            <td>
                Manager Khusus
            </td>
            <td><select name="khusus" id="khusus">
                    <option value="">-Pilih Manager Khusus-</option>
                    <option value="1">Satu Bulan</option>
                    <option value="2">Dua Bulan</option>
                    <option value="3">Tiga Bulan</option>
                </select> </td>
        </tr>
        <tr>

            <td colspan="2" align="center">
                <input type="hidden" name="strkode_dealer"  id="strkode_dealer" value="<?php echo $strkode?>">
                    <?php echo '<br />'.form_submit('submit','Proses','id="submit3" class="button"')?></td>
        </tr>
    </table>
</form>


    <?php }else {?>

<form method="post" action="<?php echo $form_action;?>">
    <table id="data">
        <tr>
            <td>Tidak Memenuhi Syarat ! Belum bisa Melanjutkan ke Calon Manager Berikutnya</td>
            <td>
                <input type="hidden" name="strkode_dealer"  id="strkode_dealer" value="<?php echo $strkode?>">
                <?php if ($this->session->userdata('privilege')== 1){?>
                <input type="submit" name="submit" value="Reset Pra Cm"> 
                <?php } ?>
            </td>
        </tr>
    </table>
</form>
    <?php } ?>

<p>&nbsp;</p>

<div id="message3"></div>

<script type="text/javascript">
    $(document).ready( function() {
        $('#submit3').click(function() {
            var form_data = {
                strkode_dealer : $('#strkode_dealer').val(),
                khusus : $('#khusus').val(),
                bulan : $('#bulan').val(),
                tahun : $('#tahun').val(),
                khusus : $('#khusus').val(),
                ajax : '1'
            };
            $.ajax({
                url: "<?php echo base_url(); ?>calon_manager/cm1",
                type: 'POST',
                async : false,
                data: form_data,
                success: function(msg) {
                    $('#message3').html(msg);
                }
            });
            return false;
        });

    });


</script>

